package com.lintcode.solution;

public class Solution_488 {
    public static void main(String[] args) {
        int n = 24;
        System.out.println(isHappy(n));
    }
    
    public static boolean isHappy(int n) {
        String str = String.valueOf(n);
        while (true) {
            int result = 0;
            for (Character c : str.toCharArray()) {
                int i = Integer.parseInt(c.toString());
                result += i * i;
            }
            if (result == 1) {
                return true;
            } else if (result >= 2 && result <= 9) {
                return false;
            } else {
                str = String.valueOf(result);
            }
        }
    }
}
